<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('新增分类')}" />
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
        <form class="form-horizontal m" id="form-category-add">
            <input name="channelId" th:value="${channelId}"  type="hidden"/>
            <input type="hidden" name="status" value="0" required>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label text-sm-right">上级目录</label>
                <div class="col-sm-5">
                    <div class="input-group">
                        <input id="parentId" name="parentId" type="hidden" th:value="${category !=null?category.categoryId:0}"/>
                        <input class="form-control" type="text" id="parentName" readonly="readonly" th:value="${category !=null?category.categoryName:'无'}">
                    </div>
                </div>
            </div>
            <div class="form-group row" id="subjectDisplay" th:if="${category == null}">
                <label class="col-sm-2 col-form-label text-sm-right">选择专业</label>
                <div class="col-sm-5">
                    <select id="subjectId" name="subjectId" class="form-control m-b" th:with="type=${subjects}" required>
                        <option value="0">请选择专业</option>
                        <option th:each="dict : ${type}" th:text="${dict.subjectName}" th:value="${dict.subjectId}" th:selected="${dict.subjectId == category?.subjectId}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label text-sm-right">类别名称</label>
                <div class="col-sm-8">
                    <textarea style="min-height:200px" name="categoryName"  placeholder="每个类名称用回车分隔" class="form-control"></textarea>
                    <br>
                    <span style="color:red">
                            每个类名称用回车分隔
                        </span>
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label text-sm-right">排序</label>
                <div class="col-sm-3">
                    <input name="sort" class="form-control" type="text">
                </div>
            </div>
            <input name="type" value="course" class="form-control" type="hidden">
        </form>
    </div>
    <th:block th:insert="~{include :: footer}" />
    <script type="text/javascript">
        var prefix = "/category"
        var channelId = [[${channelId}]];

        $(function (){
            /*分类-新增-选择父部门树*/
            $('#parentName').click(function () {
                var options = {
                    title: null,
                    width: "380px",
                    url: "/category/select.html?categoryId=" + $("#parentId").val() + "&channelId=" + channelId,
                    callBack: function (index, layero) {
                        var body = layer.getChildFrame('body', index);
                        setCategory(body.find('#parentId').val(), body.find('#parentName').val())
                        layer.close(index);
                    }
                };
                $.modal.openOptions(options);
            });
        });

        function setCategory(id, name) {
            $("#parentId").val(id);
            $("#parentName").val(name);
        }

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add.json", $('#form-category-add').serialize());
            }
        }

    </script>
</body>
</html>